package cn.gov.pbc.gd.credit.web.servlet;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import com.liu.tools.LogUtil;

import cn.gov.pbc.gd.credit.user.service.dictionary.IDictionaryService;


public class ContextRefreshListener implements ApplicationListener<ContextRefreshedEvent>{

	@Autowired
	private IDictionaryService dictionaryService;
	
	private static Logger logger = LoggerFactory.getLogger(ContextRefreshListener.class);
	
	@Override
	public void onApplicationEvent(ContextRefreshedEvent event) {
		if(event.getApplicationContext().getParent() == null){//root application context 没有parent
			new Thread(new Runnable() {
				
				@Override
				public void run() {
					
				        logger.info(LogUtil.msg("Init:onApplicationEvent", "开始加载数据配置表到缓存！", ""));
				        dictionaryService.initConf(null);
						logger.info(LogUtil.msg("Init:onApplicationEvent", "加载配置到缓存成功，噢耶！(~_~)", ""));
				   				
				}
			}).start();
	    }
	}

}
